package ubadb.core.components.bufferManager.bufferPool.replacementStrategies.lastUseDate;

import java.util.Date;

import ubadb.core.common.Page;
import ubadb.core.components.bufferManager.bufferPool.BufferFrame;
import ubadb.core.exceptions.BufferFrameException;

/**
 * Buffer frame that remembers the date of the last reference (pin/unpin).
 * Used for replacement strategies based on this date (LRU/MRU).
 */
public class LastUseDateBufferFrame extends BufferFrame
{
	private Date lastUseDate;
	
	public LastUseDateBufferFrame(Page page)
	{
		super(page);
		lastUseDate = new Date();
	}
	
	@Override
	public void pin()
	{
		super.pin();
		lastUseDate = new Date();
	}
	
	@Override
	public void unpin() throws BufferFrameException
	{
		super.unpin();
		lastUseDate = new Date();
	}
	
	/**
	 * @return the date of the last use (pin/unpin/creation)
	 */
	public Date getLastUseDate()
	{
		return lastUseDate;
	}
	
}
